package com.zx.job.controller;

import Job.Dto.CategoryDto;
import Job.Dto.JobDto;
import com.zx.job.mapper.CategoryMapper;
import com.zx.job.service.CategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pojo.Result;
import java.util.List;

@RestController
@RequestMapping("/category")
@RequiredArgsConstructor
@Tag(name = "岗位分类管理接口", description = "提供岗位分类相关的操作接口")
public class CategoryController {
    private final CategoryService categoryService;
    private final CategoryMapper categoryMapper;
    @GetMapping("/findByName/{name}")
    public int getIdByName(@PathVariable("name") String name){
        return categoryMapper.getIdByName(name);
    }
    @GetMapping("/getAll")
    List<CategoryDto> getAllCategories() {
        return categoryMapper.getAllCategories();
    }
    @GetMapping("/name/{id}")
    public String findNameById(@PathVariable("id") Integer id) {
        return categoryMapper.findNameById(id);
    }
    // 查询所有分类
    @GetMapping("")
    @Operation(summary = "查询所有岗位分类", description = "获取系统中所有的岗位分类信息")
    public Result<List<CategoryDto>> findAll() {
        return Result.success(categoryService.findAll());
    }

    //模糊查询分类
    @GetMapping("/name")
    @Operation(summary = "模糊查询岗位分类", description = "根据给定的名称，模糊查询符合要求的岗位分类信息")
    @Parameter(name = "name", description = "分类名称", required = true)
    public Result<List<CategoryDto>> findByName(@RequestParam String name) {
        return Result.success(categoryService.findByName(name));
    }

    // 添加分类
    @PostMapping("")
    @Operation(summary = "添加岗位分类", description = "向系统中添加新的岗位分类信息")
    @Parameter(name = "categoryDto", description = "包含岗位分类信息的对象", required = true)
    public Result<?> addCategory(@RequestBody CategoryDto categoryDto) {
        categoryService.addCategory(categoryDto);
        return Result.success();
    }

    // 删除分类
    @DeleteMapping("/{id}")
    @Operation(summary = "删除岗位分类", description = "根据给定的岗位分类ID，删除对应的岗位分类信息")
    @Parameter(name = "id", description = "岗位分类的唯一标识", required = true)
    public Result<?> deleteCategory(@PathVariable Integer id) {
        categoryService.deleteCategory(id);
        return Result.success();
    }

    // 修改分类
    @PutMapping("/{id}")
    @Operation(summary = "修改岗位分类", description = "根据给定的岗位分类ID，更新对应的岗位分类信息")
    @Parameter(name = "categoryDto", description = "包含更新后岗位分类信息的对象", required = true)
    public Result<?> updateCategory(@RequestBody CategoryDto categoryDto) {
        categoryService.updateCategory(categoryDto);
        return Result.success();
    }
}
